home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWToolbx / SLMacOS.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.6 KB  |  231 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLMacOS.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifdef FW_BUILD_MAC
  13.  
  14. #ifndef SLMACOS_H
  15. #include "SLMacOS.h"
  16. #endif
  17.  
  18. #ifndef FWPRIDEB_H
  19. #include "FWPriDeb.h"
  20. #endif
  21.  
  22. #ifndef FWSOMENV_H
  23. #include "FWSOMEnv.h"
  24. #endif
  25.  
  26. #ifndef FWRECT_H
  27. #include "FWRect.h"
  28. #endif
  29.  
  30. #ifndef FWCFMRES_H
  31. #include "FWCFMRes.h"
  32. #endif
  33.  
  34. #ifndef SLREGION_H
  35. #include "SLRegion.h"
  36. #endif
  37.  
  38. #if defined(FW_BUILD_MAC) & !defined(__RESOURCES__)
  39. #include <Resources.h>
  40. #endif
  41.  
  42. //========================================================================================
  43. //    Runtime Informations
  44. //========================================================================================
  45.  
  46. #ifdef FW_BUILD_MAC    
  47. #pragma segment fwtoolbx
  48. #endif
  49.  
  50. //========================================================================================
  51. //    Mac OS Utlities
  52. //========================================================================================
  53.  
  54. //----------------------------------------------------------------------------------------
  55. //    FW_PrivMacBuildWindowRegions
  56. //----------------------------------------------------------------------------------------
  57. //    Calculate window size including structure region (i.e. title bar). To do this we need,
  58. //    if the window isn't shown, to force the window to compute its structure region by
  59. //    calling its defproc. If build is false, set the regions back to empty regions, so
  60. //    as not to confuse the window manager. Return the previous state of the regions.
  61.  
  62. typedef pascal long(*WDefProcType)(short varCode,
  63.                                    WindowPtr theWindow,
  64.                                    short message,
  65.                                    long param);
  66.  
  67. typedef WDefProcType *WDefProcTypeHandle;
  68.  
  69. static Handle MacGetAndLoadWDefProc(Handle windowDefProc)
  70. {
  71.     if ((*windowDefProc))                        // if Master Ptr is NULL => resource is purged
  72.         return windowDefProc;
  73.     else
  74.     {
  75.         FW_SOMEnvironment ev;
  76.         FW_CAcquireCFMResourceAccess qr(ev);
  77.         ::LoadResource(windowDefProc);
  78.         if (::ResError() == noErr)                // only return it if the LoadResource worked
  79.             return windowDefProc;
  80.         else
  81.             return NULL;
  82.     }
  83. }
  84.  
  85. FW_Boolean FW_PrivMacBuildWindowRegions(WindowPtr windowPtr, FW_Boolean build, FW_PlatformError* error)
  86. {
  87.     FW_ERR_TRY
  88.     {
  89.         FW_ASSERT(windowPtr != NULL);
  90.     
  91.         WindowRecord &theWindowRecord = *((WindowPeek)windowPtr);
  92.     
  93.         // The regions are considered to be built if either:
  94.         //  a) the window is shown; or
  95.         //  b) the structure rgn is not empty.
  96.     
  97.         if (theWindowRecord.visible || !::EmptyRgn(theWindowRecord.strucRgn))
  98.         {
  99.             if ((build != true) && !theWindowRecord.visible)
  100.             {
  101.                 ::SetEmptyRgn(theWindowRecord.strucRgn);
  102.                 ::SetEmptyRgn(theWindowRecord.contRgn);
  103.             }
  104.             return true;
  105.         }
  106.         else
  107.         {
  108.             if (build == true)
  109.             {
  110.                 WDefProcTypeHandle wDefProc = (WDefProcTypeHandle)MacGetAndLoadWDefProc(theWindowRecord.windowDefProc);
  111.                 if (wDefProc)
  112.                 {
  113.                     SignedByte savedState = ::HGetState((Handle)wDefProc);
  114.                     ::HLock((Handle)wDefProc);
  115.     //                WindowDefUPP windowDefUPP = NewWindowDefProc(*wDefProc);
  116.                     WindowDefUPP windowDefUPP = (WindowDefUPP) NewRoutineDescriptor((ProcPtr)(*wDefProc), uppWindowDefProcInfo, ((ISAType) kM68kISA));
  117.                     if (windowDefUPP == NULL)
  118.                         *error = FW_xMemoryExhausted;
  119.                     else
  120.                     {
  121.                         CallUniversalProc(windowDefUPP, uppWindowDefProcInfo, ::GetWVariant(windowPtr), windowPtr, wCalcRgns, 0);
  122.                         DisposeRoutineDescriptor(windowDefUPP);
  123.                         ::HSetState((Handle)wDefProc, savedState);
  124.                     }
  125.                 }
  126.             }
  127.             return false;
  128.         }
  129.     }
  130.     FW_ERR_CATCH
  131.     
  132.     return false;
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. // FW_MacGetMaxIntersectedDevice
  137. //----------------------------------------------------------------------------------------
  138.  
  139. GDHandle  FW_MacGetMaxIntersectedDevice(WindowPtr windowPtr, FW_SRect& screenRect, FW_PlatformError* error)
  140. {
  141.     GDHandle maxSectGD = NULL;
  142.  
  143.     FW_ERR_TRY
  144.     {
  145.         FW_ASSERT(windowPtr != NULL);
  146.         
  147.         FW_Boolean rgnsWereBuilt = FW_PrivMacBuildWindowRegions(windowPtr, true, error);
  148.         if (*error)
  149.             return NULL;
  150.     
  151.         Rect globalStrucRect = (*(((WindowPeek)windowPtr)->strucRgn))->rgnBBox;
  152.         FW_PrivMacBuildWindowRegions(windowPtr, rgnsWereBuilt, error);
  153.         if (*error)
  154.             return NULL;
  155.         
  156.         long maxSectArea = 0;
  157.         Rect moveBounds = (*(GetGrayRgn()))->rgnBBox;
  158.         InsetRect(&moveBounds, 4, 4);
  159.     
  160.         GDHandle aGDHandle = ::GetDeviceList();
  161.         maxSectGD = ::GetMainDevice();    // Set as best choice default 
  162.         while (aGDHandle)
  163.         {                                        // calc which scrn intersects largest part of window
  164.             if (::TestDeviceAttribute(aGDHandle, screenDevice) && ::TestDeviceAttribute(aGDHandle, screenActive))
  165.             {
  166.                 Rect aGDScreenRect = (*aGDHandle)->gdRect;
  167.                 Rect gdSectRect;
  168.                 Rect dontCare;
  169.                 if (::SectRect(&aGDScreenRect, &moveBounds, &dontCare) && ::SectRect(&globalStrucRect, &aGDScreenRect, &gdSectRect))
  170.                 {
  171.                     long sectArea = (gdSectRect.bottom - gdSectRect.top) * (gdSectRect.right - gdSectRect.left);
  172.                     if (sectArea > maxSectArea)    // do we have a new winner? 
  173.                     {
  174.                         maxSectArea = sectArea;
  175.                         maxSectGD = aGDHandle;
  176.                     }
  177.                 }
  178.             }
  179.             aGDHandle = ::GetNextDevice(aGDHandle);
  180.         }
  181.     
  182.         FW_CRect* castedRect = (FW_CRect*)&screenRect;
  183.         
  184.         if (maxSectGD != ::GetMainDevice())
  185.             *castedRect = (*maxSectGD)->gdRect;
  186.         else
  187.         {
  188.             // Account for menu bar on the main screen.
  189.             // Don't just assume that its at the top of
  190.             // the screen!
  191.             Rect gdRect = (*maxSectGD)->gdRect;
  192.     
  193.             RgnHandle tempRgn = ::FW_NewRegion();
  194.             if (tempRgn == NULL)
  195.             {
  196.                 *error = FW_xMemoryExhausted;
  197.                 return NULL;
  198.             }
  199.             ::RectRgn(tempRgn, &gdRect);                // main screen with menubar 
  200.             ::SectRgn(tempRgn, GetGrayRgn(), tempRgn);    // GetGrayRgn == desktop rgn w/o menubar 
  201.             *castedRect = (*tempRgn)->rgnBBox;            // => main screen w/o menubar 
  202.             ::FW_DisposeRegion(tempRgn);
  203.         }
  204.     }
  205.     FW_ERR_CATCH
  206.  
  207.     return maxSectGD;
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //  FW_MacZoomWindow: 
  212. //----------------------------------------------------------------------------------------
  213.  
  214. FW_PlatformError FW_MacZoomWindow(WindowPtr windowPtr, FW_Boolean zoomIn)
  215. {
  216.     // No try block necessary - Do not throw
  217.     GrafPtr curGrafPort;
  218.     ::GetPort(&curGrafPort);
  219.     ::SetPort(windowPtr);                                // The ROM requires that thePort be the window being zoomed.
  220.  
  221.     ::ClipRect(&windowPtr->portRect);
  222.     ::EraseRect(&windowPtr->portRect);
  223.     ::ZoomWindow(windowPtr, zoomIn ? inZoomIn : inZoomOut, false);
  224.  
  225.     ::SetPort(curGrafPort);
  226.     
  227.     return FW_xNoError;
  228. }
  229.  
  230. #endif
  231.